package binarytree

type BSTIterator struct {
	nums []int
}

func Constructor173(root *TreeNode) BSTIterator {
	dlr_res := []int{}
	var dlr func(*TreeNode)
	dlr = func(root *TreeNode) {
		if root == nil {
			return
		}
		dlr(root.Left)
		dlr_res = append(dlr_res, root.Val)
		dlr(root.Right)
	}
	dlr(root)

	return BSTIterator{nums: dlr_res}
}

func (this *BSTIterator) Next() int {
	var val int
	if len(this.nums) == 0 {
		return -1
	}
	val = this.nums[0]
	if len(this.nums) == 1 {
		this.nums = []int{}
	} else {
		this.nums = this.nums[1:]
	}
	return val
}

func (this *BSTIterator) HasNext() bool {
	return len(this.nums) > 0
}
